package com.huaxindata.common.base;

import android.content.Intent;
import android.os.Bundle;

import com.huaxindata.common.util.HxActivityManger;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @author songxf
 * @date 2017/9/20
 * @Desc Activity基类
 * Copyright HUAXIN DATA. All rights reserved.
 */
public abstract class HxBaseActivity extends HxBaseLayoutActivity {

    private Unbinder mUnbinder;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getContentViewId());
        //通过注解绑定控件
        mUnbinder = ButterKnife.bind(this);
        onCreateNew(savedInstanceState);
        getInitData();
        HxActivityManger.getAppManager().addActivity(this);
    }

    /**
     * 布局文件id
     *
     * @return
     */
    public abstract int getContentViewId();

    /**
     * 初始化view
     */
    public abstract void onCreateNew(Bundle savedInstanceState);

    /**
     * 初始化data
     */
    public abstract void getInitData();


    /**
     * 根据传入的类(class)打开指定的activity
     *
     * @param pClass
     */
    public void openActivity(Class<?> pClass) {
        Intent itent = new Intent();
        itent.setClass(this, pClass);
        startActivity(itent);
    }

    @Override
    protected void onDestroy() {
        if (mUnbinder != null) {
            mUnbinder.unbind();
        }
        HxActivityManger.getAppManager().finishActivity(this);
        super.onDestroy();
    }

}
